package com.newedu.equipmgr.servlet.equipment.area;

import com.alibaba.fastjson.JSON;
import com.newedu.equipmgr.entity.AreaInfo;
import com.newedu.equipmgr.service.AreaService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author jerry
 * @create 2020-06-10 10:53:28
 * @company 新开普电子股份有限公司
 */
@WebServlet(name = "AreaInfoQueryByBuildingServlet",urlPatterns = "/api/servlet/area/queryByBuilding")
public class AreaInfoQueryByBuildingServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String building = request.getParameter("building");
        AreaService areaInfoService = new AreaService();

        String condition = "";
        if(building!=null & !building.isEmpty()){
            condition += " and building = '"+building+"'";
        }
        List<AreaInfo> list = areaInfoService.selectAreaInfoBy(condition);
        String result = JSON.toJSONString(list);
        response.getWriter().println(result.toString());
        response.getWriter().flush();
        response.getWriter().close();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
